<?php
namespace app\admin\model;
use think\Model;
use app\admin\model\BaseModel;
class Areas extends BaseModel
{	
	const HK_ID = 130; //香港id
	const CHINA_ID = 1; //大陆id
	/*获取到地址*/
	public static function getItemAddressLabel($item_id){
		$row = db('pops')->where(['id'=>$item_id])->find();
		if(empty($row)){
			return null;
		}
		$popIds = [intval($row['area_id']),intval($row['city_id'])];
		$area = self::getAreaLabel($popIds);
		return $area." ".$row['address'];
	}
	/*获取地址*/
	public static function getAreaLabel($ids){
		$pops = self::where("id","in",$ids)->order('name'.self::prexLang().' asc,id asc')->column('id,name'.self::prexLang()." as name" ,'id');
		
		return empty($pops) ? '' : implode(" ", array_values($pops));
	}
	public static function getAreas($pid=0){
		$lists = self::where(['status'=>1,'pid'=>$pid])->field('id,name'.self::prexLang().' as name,icon')->order('name'.self::prexLang().' asc,sort asc')->select();
		return empty($lists) ? [] : $lists;
	}
	public static function getAreaName($id=0){
		$name = self::where(['id'=>$id])->value('name'.self::prexLang());
		return empty($name) ? '--' : $name;
	}
	public static function getNameLabel($id=0){
		$name = self::where(['id'=>$id])->value('name'.self::prexLang());
		return empty($name) ? '--' : $name;
	}
	public function getNameAttr($value,$data){
		$name = $data['name'.$this->prexLang()];
		return empty($name) ? $value : $name;
	}
	public static function getArealocation($name,$condition=[]){
		return $location_id = self::where($condition)->value($name);
	}
	
}